<?php


namespace app\api\controller\service;


use app\common\controller\Api;
use think\Db;

class Activity extends Api
{
    protected $noNeedLogin = ['*'];

    public function info()
    {
        $model = new \app\admin\model\service\info\Activity();
        $list = $model->find()->toArray();
        $data = [];
        foreach ($list as $k => $v) {
            if ($k != 'id' && $k != 'menu_icon') {
                $data[$k] = Db::name('service_goods')
                    ->where('id', $list[$k])
                    ->field('id,name,tag_name,price,image')->find();
            }
        }
        if ($data) {
            $this->success('信息返回成功', $data);
        } else {
            $this->error('信息异常');
        }
    }

    public function menuIcon()
    {
        $model = new \app\admin\model\service\info\Activity();
        $list = $model->find()->toArray();

        if ($list) {
            $this->success('信息返回成功', $list['menu_icon']);
        } else {
            $this->error('信息异常');
        }
    }

    public function skillRankingList()
    {
        $type = input('type/string', 'salenums');
        if ($type != 'salenums' && $type != 'zan_num') {
            $this->error('参数错误');
        }
        $list = Db::name('service_skill')
//          ->where('id', $list[$k])
            ->order($type, 'DESC')
            ->limit(0, 8)
            ->field('name,image,salenums,zan_num')
            ->select();

        if ($list) {
            $this->success('信息返回成功', $list);
        } else {
            $this->error('信息异常');
        }
    }
}